package com.bitsbazaar.manager;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import com.bitsbazaar.dao.BaseDao;
import com.bitsbazaar.entity.Image;
import com.bitsbazaar.entity.User;

public class ImageManagerImpl implements ImageManager {


	
	private BaseDao dao;
	
	public BaseDao getDao() {
		return dao;
	}

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}

	
	
	
	@Override
	public Long createImage(Image image) {
		// TODO Auto-generated method stub
		return dao.save(image);
	}

	@Override
	public Image getImageById(Long id) {
		// TODO Auto-generated method stub
		return (Image) dao.findById(Image.class, id);
	}

	@Override
	public Boolean updateImage(Image image) {
		// TODO Auto-generated method stub
		return dao.update(image);
	}

	@Override
	public Boolean deleteImageById(Long id) {
		// TODO Auto-generated method stub
		return dao.deleteById(Image.class, id);
	}

	@Override
	public List<Image> getImageByParentId(Long parentId) {
		// TODO Auto-generated method stub
	return (List<Image>)(List<?>)dao.findByProperty(Image.class,"parentId", parentId);
	}

	@Override
	public byte[] convertImage(File file) {
		// TODO Auto-generated method stub
		
		
		byte[] bFile = new byte[(int) file.length()];
		try {
			FileInputStream fileInputStream = new FileInputStream(file);
			fileInputStream.read(bFile);
			fileInputStream.close();
			} catch (Exception e) {
		
				e.printStackTrace();
		
			}
		
		return bFile;
	}

}
